home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v9n08.arc / KBBUFFER.ASM < prev    next >
Assembly Source File  |  1990-03-30  |  11KB  |  289 lines

  1. ;---------------------------------------------------------------;
  2. ;  KBBUFFER.CTL * PC Magazine * Michael J. Mefford              ;
  3. ;  Is loaded as a device driver just to get within offset       ;
  4. ;  range of the BIOS data area and the keyboard buffer so       ;
  5. ;  it can replace the default 15 key buffer with a larger one.  ;
  6. ;---------------------------------------------------------------;
  7.  
  8. BIOS_DATA      SEGMENT AT 40H
  9.                ORG     1AH
  10. BUFFER_HEAD    DW      ?
  11. BUFFER_TAIL    DW      ?
  12.                ORG     80H
  13. BUFFER_START   DW      ?
  14. BUFFER_END     DW      ?
  15. BIOS_DATA      ENDS
  16.  
  17.  
  18. _TEXT          SEGMENT PUBLIC 'CODE'
  19.                ASSUME  CS:_TEXT,DS:_TEXT,ES:_TEXT,SS:_TEXT
  20.  
  21.                ORG     0H
  22.  
  23. ;COPYRIGHT      DB     "KBBUFFER.CTL 1.0 (c) 1989 Ziff Communications Co.",CR,LF
  24. ;PROGRAMMER     DB     "PC Magazine ",BOX," Michael J. Mefford",CR,LF,CTRL_Z
  25.  
  26. ;************* DEVICE_HEADER *************;
  27.  
  28. POINTER        DD      -1
  29. ATTRIBUTE      DW      1000000000000000B
  30. DEVICE_STRAG   DW      STRATEGY
  31. DEVICE_INT     DW      INTERRUPT
  32. DEVICE_NAME    DB      "BUFFERCTL"
  33.  
  34.  
  35. CR             EQU     13
  36. LF             EQU     10
  37. CTRL_Z         EQU     26
  38. SPACE          EQU     32
  39. BOX            EQU     254
  40.  
  41. ;-------------------------;
  42.  
  43. REQUEST_HEADER STRUC
  44.  
  45. HEADER_LENGTH  DB      ?
  46. UNIT_CODE      DB      ?
  47. COMMAND_CODE   DB      ?
  48. STATUS         DW      ?
  49. RESERVED       DQ      ?
  50.  
  51. REQUEST_HEADER ENDS
  52.  
  53. DONE           EQU     0000000100000000B       ;Status codes.
  54. UNKNOWN        EQU     1000000000000011B
  55.  
  56. ;-------------------------;
  57.  
  58. INIT           STRUC
  59.  
  60. HEADER         DB      (TYPE REQUEST_HEADER) DUP(?)
  61. UNITS          DB      ?
  62. ENDING_OFFSET  DW      ?
  63. ENDING_SEGMENT DW      ?
  64. ARGUMENTS_OFF  DW      ?
  65. ARGUMENTS_SEG  DW      ?
  66.  
  67. INIT           ENDS
  68.  
  69. REQUEST_OFFSET DW      ?
  70. REQUEST_SEG    DW      ?
  71.  
  72. ;              CODE AREA
  73. ;              ---------
  74.  
  75. ;---------------------------------------------;
  76. ; The only task of the strategy routine is to ;
  77. ; save the pointer to the request header.     ;
  78. ;---------------------------------------------;
  79.  
  80. STRATEGY       PROC    FAR
  81.  
  82.                MOV     CS:REQUEST_OFFSET,BX    ;Request header address is
  83.                MOV     CS:REQUEST_SEG,ES       ; passed in ES:BX.
  84.                RET
  85.  
  86. STRATEGY       ENDP
  87.  
  88. ;------------------------------------------------------------------------;
  89. ; The interrupt procedure will be called immediately after the strategy. ;
  90. ;------------------------------------------------------------------------;
  91.  
  92. INTERRUPT      PROC    FAR
  93.  
  94.                PUSH    AX                      ;Responsible for all registers.
  95.                PUSH    BX
  96.                PUSH    CX
  97.                PUSH    DX
  98.                PUSH    DS
  99.                PUSHF
  100.  
  101.                MOV     DS,CS:REQUEST_SEG       ;Retrieve request header pointer.
  102.                MOV     BX,CS:REQUEST_OFFSET
  103.  
  104.                OR      STATUS[BX],DONE         ;Tell DOS we are done.
  105.                CMP     COMMAND_CODE[BX],0      ;Is it INIT command?
  106.                JZ      MAKE_STACK              ;If yes, do our stuff.
  107.                OR      STATUS[BX],UNKNOWN      ;Else, exit with confused
  108.                JMP     SHORT UNKNOWN_EXIT      ; message to DOS.
  109.  
  110. MAKE_STACK:    MOV     CX,SS                   ;Save DOS stack.
  111.                MOV     DX,SP
  112.                MOV     AX,CS
  113.                CLI
  114.                MOV     SS,AX                   ;Make new stack.
  115.                MOV     SP,0FFFEH
  116.                STI
  117.                PUSH    CX                      ;Save old stack pointers on new.
  118.                PUSH    DX
  119.  
  120.                PUSH    ES                      ;Save rest of registers.
  121.                PUSH    SI
  122.                PUSH    BP
  123.  
  124.                CALL    INITIALIZE              ;Go do our stuff.
  125.  
  126.                POP     BP                      ;Restore registers.
  127.                POP     SI
  128.                POP     ES
  129.  
  130.                POP     DX                      ;Restore old DOS stack.
  131.                POP     CX
  132.                CLI
  133.                MOV     SS,CX
  134.                MOV     SP,DX
  135.                STI
  136.  
  137. UNKNOWN_EXIT:  POPF                            ;Restore rest of registers.
  138.                POP     DS
  139.                POP     DX
  140.                POP     CX
  141.                POP     BX
  142.                POP     AX
  143.                RET                             ;Far return back to DOS.
  144.  
  145. INTERRUPT      ENDP
  146.  
  147. KBBUFFER_CTL_END LABEL   WORD
  148.  
  149. ;************* END OF RESIDENT PORTION *************;
  150.  
  151. BUFFER_DEFAULT EQU     80
  152. BUFFER_MIN     EQU     16
  153. BUFFER_MAX     EQU     200
  154.  
  155. HEADING        LABEL   BYTE
  156.  
  157. DB "KBBUFFER.CTL 1.0 (C) 1989 Ziff Communications Co.",CR,LF
  158. DB "PC Magazine ",BOX," Michael J. Mefford",CR,LF,LF,"$"
  159.  
  160. INSTALLED_MSG  LABEL   BYTE
  161.  
  162. DB "Installed",CR,LF,LF
  163.  
  164. DB "Syntax:  DEVICE = KBBUFFER.CTL [buffer size]",CR,LF
  165. DB "buffer size = 16 - 200",CR,LF
  166. DB "default = 80",CR,LF,LF,"$"
  167.  
  168. OUT_OF_RANGE_MSG  LABEL BYTE
  169.  
  170. DB "KBBUFFER.CTL is loaded greater than 64K from BIOS data area",CR,LF
  171. DB "KBBUFFER is inactive",CR,LF
  172. DB "Make sure KBBUFFER.CTL is first in CONFIG.SYS",CR,LF,LF,"$"
  173.  
  174. ;              ***************
  175. ;              * SUBROUTINES *
  176. ;              ***************
  177.  
  178. ;------------------------------------------;
  179. ; INPUT                                    ;
  180. ;   DS:BX points to request header.        ;
  181. ;                                          ;
  182. ;   All registers destroyed.               ;
  183. ;------------------------------------------;
  184.  
  185. INITIALIZE     PROC    NEAR
  186.  
  187.                PUSH    DS                      ;Point to request segment.
  188.                POP     ES
  189.                MOV     ENDING_OFFSET[BX],OFFSET KBBUFFER_CTL_END
  190.                MOV     ENDING_SEGMENT[BX],CS   ;Resident portion setup.
  191.  
  192.                MOV     CX,ARGUMENTS_SEG[BX]    ;Retrieve CONFIG.SYS buffer
  193.                MOV     SI,ARGUMENTS_OFF[BX]    ; pointers from INIT table.
  194.  
  195.                PUSH    CS                      ;Point to our data.
  196.                POP     DS
  197.                MOV     DX,OFFSET HEADING       ;Display signature.
  198.                CALL    PRINT_STRING
  199.  
  200.                MOV     DS,CX                   ;Point to argument segment.
  201.                CLD
  202.  
  203. ;------------------------------------;
  204. ; Parse CONFIG.CTL second parameter. ;
  205. ;------------------------------------;
  206.  
  207. FIND_PARA:     LODSB                           ;Get a byte.
  208.                CMP     AL,SPACE                ;Leading white space?
  209.                JA      FIND_PARA               ;If yes, parse it off.
  210.  
  211.                DEC     SI                      ;Point to start of argument.
  212.                XOR     BP,BP                   ;Use BP to store seconds.
  213. NEXT_NUMBER:   LODSB                           ;Retrieve a byte.
  214.                CMP     AL,CR                   ;If carriage return or linefeed,
  215.                JZ      CK_PARA                 ; found end of parameter.
  216.                CMP     AL,LF
  217.                JZ      CK_PARA
  218.                SUB     AL,"0"                  ;ASCII to binary.
  219.                JC      NEXT_NUMBER             ;If not between 0 and 9, skip.
  220.                CMP     AL,9
  221.                JA      NEXT_NUMBER
  222.                CBW                             ;Convert to word.
  223.                XCHG    AX,BP                   ;Swap old and new number.
  224.                MOV     CX,10                   ;Shift to left by multiplying
  225.                MUL     CX                      ; last entry by ten.
  226.                ADD     BP,AX                   ;Add new number and store in BP.
  227.                JMP     SHORT NEXT_NUMBER
  228.  
  229. ;---------------------------------------------;
  230. ; Check minimum, maximum parameter boundaries ;
  231. ;---------------------------------------------;
  232.  
  233. CK_PARA:       CMP     BP,BUFFER_MIN           ;Is it below 16?
  234.                JA      CK_MAX
  235.                MOV     BP,BUFFER_DEFAULT       ;If yes, use default 80.
  236. CK_MAX:        CMP     BP,BUFFER_MAX           ;Is it above 200?
  237.                JBE     CK_SEGMENT
  238.                MOV     BP,BUFFER_MAX           ;If yes, use default 80.
  239.  
  240. ;----------------------------------------------------------------;
  241. ; Check to see if KBBUFFER.CTL is within 64K range.  If it is,   ;
  242. ; change keyboard buffer to point to us, else exit with message. ;
  243. ;----------------------------------------------------------------;
  244.  
  245. CK_SEGMENT:    INC     BP                          ;Adjust.
  246.                SHL     BP,1                        ;Convert byte count to word.
  247.                MOV     DX,OFFSET OUT_OF_RANGE_MSG  ;Point to out of range msg.
  248.                MOV     AX,CS                       ;Retrieve our segment.
  249.                SUB     AX,SEG BIOS_DATA            ;Subtract BIOS data segment.
  250.                MOV     CX,4                        ;AX = distance in paragraphs;
  251. PARA_TO_BYTES: SHL     AX,1                        ; convert to bytes.
  252.                JC      INIT_END                    ;If > 64K, exit.
  253.                LOOP    PARA_TO_BYTES
  254.                ADD     AX,OFFSET KBBUFFER_CTL_END  ;Add resident portion offset.
  255.                JC      INIT_END                    ;If > 64K, exit.
  256.                MOV     CX,AX
  257.                ADD     CX,BP                       ;Add requested buffer size.
  258.                JC      INIT_END                    ;If > 64K, exit.
  259.  
  260. IN_RANGE:      ADD     ES:ENDING_OFFSET[BX],BP     ;Point to end of resident.
  261.                ASSUME  DS:BIOS_DATA                ;Point to BIOS data area.
  262.                MOV     DX,SEG BIOS_DATA
  263.                MOV     DS,DX
  264.  
  265.                CLI                                 ;No interrupts.
  266.                MOV     BUFFER_HEAD,AX              ;Change keyboard buffer
  267.                MOV     BUFFER_TAIL,AX              ; pointers to point to us.
  268.                MOV     BUFFER_START,AX
  269.                MOV     BUFFER_END,CX
  270.                STI                                 ;Interrupts back on.
  271.  
  272.                MOV     DX,OFFSET INSTALLED_MSG     ;Display install msg.
  273.  
  274. INIT_END:      PUSH    CS                          ;Point to our data.
  275.                POP     DS
  276.                CALL    PRINT_STRING                ;Display message.
  277.                RET                                 ;Exit.
  278.  
  279. INITIALIZE     ENDP
  280.  
  281. ;------------------------------;
  282.  
  283. PRINT_STRING:  MOV     AH,9                    ;Print string via DOS.
  284.                INT     21H
  285.                RET
  286.  
  287. _TEXT          ENDS
  288.                END
  289.